﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace BaoVeBienCuong.Store
{
    public class ButtonMenu
    {
        private int Type;
        //0 : batdau, 1 : cai dat, 2 :thanh tich
        //3 : download, 4 : share , 5 : infor , 6: off
        private Vector2 position;
        private Vector2 size;
        private Texture2D image;
        private bool isSelect;
        private float scale = 2.0f / 3.0f;
       
        public ButtonMenu(int type)
        {
            Type = type;
            if (Type <= 2)
                size = new Vector2(360, 112) * scale;
            else if (Type > 2)
                size = new Vector2(87, 87) * scale;
         
            isSelect = false;
        }
        public void setScale(float f)
        {
            scale = f;
        }
        public void setType(int type)
        {
            Type = type;
            if (Type <= 2)
                position = new Vector2(550, 20+ Type * 90);
            else
                position = new Vector2(300+ Type * 70, Type%2 == 0? 370: 420);
        }
        public void Load(ContentManager content)
        {
            if (Type <= 2)
            {
                image = content.Load<Texture2D>("images/menu/menuButton");
            }
            if (Type > 2)
            {
                image = content.Load<Texture2D>("images/menu/standardButton");
            }
        }
        public void Draw(SpriteBatch sprite)
        {

            #region
            if (Type == 0)
            {
                if (isSelect)
                {
                    sprite.Draw(image, position, new Rectangle(365, 0, 365, 112), Color.White, 0.0f, Vector2.Zero, scale, SpriteEffects.None, 1.0f);
                 
                }
                else
                {
                    sprite.Draw(image, position, new Rectangle(0, 0, 365, 112), Color.White, 0.0f, Vector2.Zero, scale, SpriteEffects.None, 1.0f);
                 
                }
            }
            else if (Type == 1)
            {
                if (isSelect)
                {
                    sprite.Draw(image, position, new Rectangle(365, 112, 365, 112), Color.White, 0.0f, Vector2.Zero, scale, SpriteEffects.None, 1.0f);
                  
                }
                else
                {
                    sprite.Draw(image, position, new Rectangle(0, 112, 365, 112), Color.White, 0.0f, Vector2.Zero, scale, SpriteEffects.None, 1.0f);
                 
                }
            }
            else if (Type == 2)
            {
                if (isSelect)
                {
                    sprite.Draw(image, position, new Rectangle(365, 224, 365, 112), Color.White, 0.0f, Vector2.Zero, scale, SpriteEffects.None, 1.0f);
                
                }
                else
                {
                    sprite.Draw(image, position, new Rectangle(0, 224, 365, 112), Color.White, 0.0f, Vector2.Zero, scale, SpriteEffects.None, 1.0f);
                  
                }
            }

            #endregion
            #region
            else if (Type == 3)
            {
                if (isSelect)
                {
                    sprite.Draw(image, position, new Rectangle(87, 87, 87, 87), Color.White, 0.0f, Vector2.Zero, scale, SpriteEffects.None, 1.0f);
                }
                else
                {
                    sprite.Draw(image, position, new Rectangle(0, 87, 87, 87), Color.White, 0.0f, Vector2.Zero, scale, SpriteEffects.None, 1.0f);
                }
            }
            else if (Type == 4)
            {
                if (isSelect)
                {
                    sprite.Draw(image, position, new Rectangle(87, 174, 87, 87), Color.White, 0.0f, Vector2.Zero, scale, SpriteEffects.None, 1.0f);
                }
                else
                {
                    sprite.Draw(image, position, new Rectangle(0, 174, 87, 87), Color.White, 0.0f, Vector2.Zero, scale, SpriteEffects.None, 1.0f);
                }
            }
            else if (Type == 5)
            {
                if (isSelect)
                {
                    sprite.Draw(image, position, new Rectangle(87, 261, 87, 87), Color.White, 0.0f, Vector2.Zero, scale, SpriteEffects.None, 1.0f);
                }
                else
                {
                    sprite.Draw(image, position, new Rectangle(0, 261, 87, 87), Color.White, 0.0f, Vector2.Zero, scale, SpriteEffects.None, 1.0f);
                }
            }
            else
            {
                if (isSelect)
                {
                    sprite.Draw(image, position, new Rectangle(87, 348, 87, 87), Color.White, 0.0f, Vector2.Zero, scale, SpriteEffects.None, 1.0f);
                }
                else
                {
                    sprite.Draw(image, position, new Rectangle(0, 348, 87, 87), Color.White, 0.0f, Vector2.Zero, scale, SpriteEffects.None, 1.0f);
                }
            }
            #endregion
        }
        public bool isTouch(Vector2 posi)
        {
                    isSelect = false;
                    if (posi.X >= position.X && posi.X <= (position.X + size.X) && posi.Y >= position.Y && posi.Y <= (position.Y + size.Y))
                    {
                       
                        isSelect = true;
                        return true;
                    }
                    else
                    {
                       
                        return false;
                    }
                
        }
        public void setTouch(bool x)
        {
            isSelect = x;
        }
    }
}
